﻿using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Wpf.Events;
using WpfTwitterClient.Infrastructure.Events;

namespace WpfTwitterClient.Modules.Status.Views.Status
{
    public class StatusPresenter : IStatusPresenter
    {
        private IEventAggregator eventAggregator;
        private SubscriptionToken subscriptionToken;

        public StatusPresenter(IStatusView view, IEventAggregator eventAggregator)
        {
            this.View = view;
            this.View.Model = new StatusPresentationModel();
            StatusEventHandler("Ready");

            subscriptionToken = eventAggregator.GetEvent<StatusEvent>().Subscribe(StatusEventHandler, ThreadOption.UIThread, true);
        }

        private void StatusEventHandler(string message)
        {
            this.View.Model.StatusMessage = message;
        }

        public IStatusView View { get; set; }
    }
}
